package com.mzj.saas.mservice.lockManager.controller;

import com.mzj.saas.commons.ApiData;
import com.mzj.saas.commons.ResultBean;
import com.mzj.saas.mservice.lockManager.service.LockUpgradeService;
import com.mzj.saas.mservice.lockManager.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 智能锁管理升级接口
 */
@Controller
@RequestMapping("/lockUpgrade")
public class LockUpgradeController {
    @Autowired
    private LockUpgradeService lockUpgradeService;

    /**
     * 升级列表-app
     *
     * @param accessToken
     * @param type        1待升级，2升级记录
     * @param search
     * @param pageNumber
     * @param pageSize
     * @return
     */
    @GetMapping("/upgradeScaleList")
    @ResponseBody
    public ResultBean<ApiData<UpgradeScaleListVO>> upgradeScaleList(@RequestHeader String accessToken,
                                                                    @RequestParam(value = "type", required = false) Integer type,
                                                                    @RequestParam(value = "search", required = false) String search,
                                                                    @RequestParam(value = "lockTaskId", required = false) Long lockTaskId,
                                                                    @RequestParam(value = "lockName", required = false) String lockName,
                                                                    @RequestParam(value = "mac", required = false) String mac,
                                                                    @RequestParam(value = "communityId", required = false) String communityId,
                                                                    @RequestParam(value = "buildId", required = false) Long buildId,
                                                                    @RequestParam(value = "unitId", required = false) Long unitId,
                                                                    @RequestParam(defaultValue = "0") Integer pageNumber,
                                                                    @RequestParam(defaultValue = "5") Integer pageSize) {
        return lockUpgradeService.upgradeScaleList(accessToken, type, search, lockTaskId, lockName, mac, communityId, buildId, unitId, pageNumber, pageSize);
    }

    /**
     * 智能锁版本列表
     *
     * @param accessToken
     * @param pageNumber
     * @param pageSize
     * @return
     */
    @GetMapping("/versionList")
    @ResponseBody
    public ResultBean<ApiData<VersionListVO>> versionList(@RequestHeader String accessToken,
                                                          @RequestParam(defaultValue = "0") Integer pageNumber,
                                                          @RequestParam(defaultValue = "5") Integer pageSize) {
        return lockUpgradeService.versionList(accessToken, pageNumber, pageSize);
    }

    /**
     * 删除智能锁版本
     *
     * @param accessToken
     * @param id
     * @return
     */
    @GetMapping("/deleteVersion")
    @ResponseBody
    public ResultBean<Object> deleteVersion(@RequestHeader String accessToken,
                                            @RequestParam(value = "id") Long id) {
        return lockUpgradeService.deleteVersion(accessToken, id);
    }

    /**
     * 新增智能锁版本
     *
     * @param accessToken
     * @param brandId
     * @param name
     * @param file
     * @return
     */
    @PostMapping("/saveVersion")
    @ResponseBody
    public ResultBean<Object> saveVersion(@RequestHeader String accessToken,
                                          @RequestParam(value = "brandId") Long brandId,
                                          @RequestParam(value = "name") String name,
                                          @RequestParam(value = "file") MultipartFile file) {
        return lockUpgradeService.saveVersion(accessToken, brandId, name, file);
    }

    /**
     * 升级列表-企业端
     *
     * @param accessToken
     * @param pageNumber
     * @param pageSize
     * @return
     */
    @GetMapping("/upgradeTaskList")
    @ResponseBody
    public ResultBean<ApiData<UpgradeTaskListVO>> upgradeTaskList(@RequestHeader String accessToken,
                                                                  @RequestParam(defaultValue = "0") Integer pageNumber,
                                                                  @RequestParam(defaultValue = "5") Integer pageSize) {
        return lockUpgradeService.upgradeTaskList(accessToken, pageNumber, pageSize);
    }

    /**
     * 查询智能锁品牌版本
     *
     * @param accessToken
     * @param brandId
     * @return
     */
    @GetMapping("/findBrandVersion")
    @ResponseBody
    public ResultBean<List<LockVersionVO>> findBrandVersion(@RequestHeader String accessToken,
                                                            @RequestParam(value = "brandId") Long brandId) {
        return lockUpgradeService.findBrandVersion(accessToken, brandId);
    }

    /**
     * 新增智能锁升级任务
     *
     * @param accessToken
     * @param vo
     * @return
     */
    @PostMapping("/saveUpgradeTask")
    @ResponseBody
    public ResultBean<Object> saveUpgradeTask(@RequestHeader String accessToken, @RequestBody SaveUpgradeTaskVO vo) {
        return lockUpgradeService.saveUpgradeTask(accessToken, vo);
    }


}
